/**
 * 
 */
package dms.dto;

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import dms.model.Campus;
import dms.util.DateFormatUtil;

/**
 * @author 李健
 *
 */
public class BuildingDTO extends ActionForm {

	private Long id;
	private Long campus;
	private Integer floors;
	private String buildDate;
	private String description;
	private Integer dormitoryCount;
	private String name;
	private Integer capacity;
	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * @return the campus
	 */
	public Long getCampus() {
		return campus;
	}
	/**
	 * @param campus the campus to set
	 */
	public void setCampus(Long campus) {
		this.campus = campus;
	}
	/**
	 * @return the floors
	 */
	public Integer getFloors() {
		return floors;
	}
	/**
	 * @param floors the floors to set
	 */
	public void setFloors(Integer floors) {
		this.floors = floors;
	}
	/**
	 * @return the buildDate
	 */
	public String getBuildDate() {
		return buildDate;
	}
	/**
	 * @param buildDate the buildDate to set
	 */
	public void setBuildDate(String buildDate) {
		this.buildDate = buildDate;
	}
	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * @return the dormitoryCount
	 */
	public Integer getDormitoryCount() {
		return dormitoryCount;
	}
	/**
	 * @param dormitoryCount the dormitoryCount to set
	 */
	public void setDormitoryCount(Integer dormitoryCount) {
		this.dormitoryCount = dormitoryCount;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the capacity
	 */
	public Integer getCapacity() {
		return capacity;
	}
	/**
	 * @param capacity the capacity to set
	 */
	public void setCapacity(Integer capacity) {
		this.capacity = capacity;
	}
	
	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		
		ActionErrors errors = new ActionErrors();
		
		if (campus == null) {
		
			errors.add("error", new ActionMessage("缺少所属校区"));
		}
		if (name == null || name.length() == 0) {
			errors.add("error", new ActionMessage("缺少楼栋名称", false));
		}
		if (description == null || description.length() == 0) {
			errors.add("error", new ActionMessage("缺少楼栋简介", false));
		}
		try {
			DateFormatUtil.parseDate(buildDate);
		} catch (Exception e) {
			errors.add("error", new ActionMessage("日期输入错误", false));
		}
		return errors;
	}
	
	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.campus = null;
		this.name = null;
		this.description = null;
		this.buildDate = null;
		this.dormitoryCount = null;
		this.capacity = null;
		this.floors = null;
		this.id = null;
	}
}

